<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>忘记密码</title>

  {include file='common/_require'/}
</head>

<body>

  {include file='common/_header'/}

  <div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
      <div class="layui-tab layui-tab-brief" lay-filter="user">
        <ul class="layui-tab-title">
          <li class="layui-this">忘记密码</li>
        </ul>
        <div class="layui-form layui-tab-content" style="padding: 20px 0;">
          <div class="layui-tab-item layui-show">
            <div class="layui-form layui-form-pane">
              <form method="post">
                <div class="layui-form-item">
                  <label class="layui-form-label">邮箱</label>
                  <div class="layui-input-inline">
                    <input type="text" name="email" required lay-verify="required" autocomplete="off" class="layui-input">
                  </div>
                  <div class="layui-form-mid send-message" style="color: #4f99cf;cursor: pointer;">发送验证邮件</div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">验证码</label>
                  <div class="layui-input-inline">
                    <input type="text" name="code" required lay-verify="required" autocomplete="off" class="layui-input">
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">新密码</label>
                  <div class="layui-input-inline">
                    <input type="password" name="password" required lay-verify="required" autocomplete="off" class="layui-input">
                  </div>
                </div>
                <div class="layui-form-item">
                  <button class="layui-btn" lay-filter="*" lay-submit>立即提交</button>
                  <span style="padding-left:20px;">
                    <a href="{:url('Login/index')}">去登陆</a>
                  </span>
                </div>

              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  {include file='common/_footer'/}


  <script>

    layui.use(['form'], function () {
      var form = layui.form;

      form.on('submit(*)', function (data) {
        console.log(data);

        $.post('{:url("forgetSave")}', data.field, function (result) {
          if (result.code == 0) {
            layer.msg('提交成功');

            setTimeout(() => {
              location.href = '{:url("Index/index")}'
            }, 1200);
          } else {
            layer.msg(result.msg)
          }
        })

        return false
      })

      $('.send-message').click(function () {
        var item = this;
        if ($(item).text() != '发送验证邮件') {
          return false;
        }
        window.loading = layer.load();
        $.post('{:url("emailSendCode")}', {
          email: $('input[name="email"]').val()
        }, function (result) {
          layer.close(window.loading);
          if (result.code == 0) {
            layer.msg('发送成功,请注意查收')
            var second = 59;
            $(item).text(second + '秒后重新发送');
            var timer = setInterval(() => {
              $(item).text(second + '秒后重新发送');
              second--;

              if (second <= 1) {
                $(item).text('发送验证邮件')
                clearInterval(timer)
              }
            }, 1000);
          } else {
            layer.msg(result.msg)
          }
        })
      })
    })

  </script>
</body>

</html>